home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / strcpy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-01  |  2.1 KB  |  84 lines

  1. /* This file is part of XEmacs.
  2.  
  3. XEmacs is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the
  5. Free Software Foundation; either version 2, or (at your option) any
  6. later version.
  7.  
  8. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11. for more details.
  12.  
  13. You should have received a copy of the GNU General Public License
  14. along with XEmacs; see the file COPYING.  If not, write to the Free
  15. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  16.  
  17. /* Synched up with: Not in FSF. */
  18.  
  19. /* In SunOS 4.1.1 the strcpy function references memory past the last byte of 
  20.    the string!  This will core dump if the memory following the last byte is 
  21.    not mapped.
  22.  
  23.    Here are correct versions by hbs@lucid.com.
  24. */
  25.  
  26.  
  27. #define ALIGNED(x) (!(((unsigned long) (x)) & (sizeof (unsigned long) - 1)))
  28.  
  29. #define MAGIC    0x7efefeff
  30. #define HIGH_BIT_P(c) ((c) & hi_bit)
  31. #define HAS_ZERO(c) (((((c) + magic) ^ (c)) & not_magic) != not_magic)
  32.  
  33. char *
  34. strcpy (char *to, const char *from)
  35. {
  36.   char *return_value = to;
  37.   if (to == from)
  38.     return to;
  39.   else if (ALIGNED (to) && ALIGNED (from))
  40.     {
  41.       unsigned long *to1 = (unsigned long *) to;
  42.       const unsigned long *from1 = (const unsigned long *) from;
  43.       unsigned long c;
  44.       unsigned long magic = MAGIC;
  45.       unsigned long not_magic = ~magic;
  46. /*      unsigned long hi_bit = 0x80000000; */
  47.  
  48.       while ((c = *from1) != 0)
  49.         {
  50.           if (HAS_ZERO(c)) 
  51.             {
  52.               to = (char *) to1;
  53.               from = (const char *) from1;
  54.               goto slow_loop;
  55.             }
  56.           else
  57.             {
  58.               *to1 = c;
  59.               to1++; 
  60.               from1++;
  61.             }
  62.         }
  63.  
  64.       to = (char *) to1;
  65.       *to = (char) 0;
  66.       return return_value;
  67.     }
  68.   else
  69.     {
  70.       char c;
  71.  
  72.     slow_loop:
  73.  
  74.       while ((c = *from) != 0)
  75.         {
  76.           *to = c;
  77.           to++;
  78.           from++;
  79.         }
  80.       *to = (char) 0;
  81.     }
  82.   return return_value;
  83. }
  84.